package game;

import boundaryToMatador.GUI;

import java.awt.Color;
import java.util.Map;

public class GUIin {
	private Map<String, String> translations;
	
	public GUIin(Map<String, String> translations) {
		this.translations = translations;
	}
	
	public int getNumberOfPlayers()
	{
		return GUI.getUserInteger(this.translations.get("GUI_IN_HOW_MANY_PLAYERS"), 2, 6);
	}
	
	public Player[] addPlayers(Player[] p)
	{
		Color[] c = {Color.LIGHT_GRAY, Color.ORANGE, Color.BLACK, Color.PINK, Color.YELLOW, Color.MAGENTA};
		for (int i=0; i<p.length; i++)
		{
			p[i]= new Player();
			p[i].setName(GUI.getUserString("Player "+(i+1)+"'s name:"));
			while (i>0) {
				boolean out=true;
				for (int k=0; k<i; k++)
				{
					if (p[i].compareName(p[k].getName())) {
						p[i].setName(GUI.getUserString(this.translations.get("GUI_IN_NAME_IS_TAKEN")));
					}
				}
				for (int k=0; k<i; k++)
				{
					if (p[i].compareName(p[k].getName())) {
						out=false;
					}
				}
				if (out) break;
			}
			GUI.addPlayer(p[i].getName(), p[i].getAccount(), c[i]);
			GUI.setCar(1, p[i].getName());
		}
		
		return p;
	}
	
	public boolean yesOrNo(boolean enoughMoney, String playerName, String propertyName) {
		String yesTxt = this.translations.get("GAME_YES");
		String noTxt = this.translations.get("GAME_NO");
		if (!enoughMoney) {
			GUI.getUserButtonPressed(this.translations.get("GUI_IN_NOT_ENOUGH_MONEY_TO_BUY"), "OK");
			return false;
		} else if(GUI.getUserButtonPressed(playerName+this.translations.get("GUI_IN_BUY_PROPERTY")+": "+propertyName, yesTxt, noTxt) == yesTxt) {
			GUI.showMessage(this.translations.get("GUI_IN_NOW_ONWER"));	
			return true;
		} else {
			return false;	
		}
	}
	
	public boolean landOnTax(int account) {
	
		GUI.showMessage("You landed on Caravan.");
		if(GUI.getUserButtonPressed("Do you want to pay 4000 or 10% of your assets","4000",Integer.toString(account/10))=="4000") {
			return true;
		}
		else {
			return false;
		}
	}
	
	public boolean playAgain()
	{
		String yesTxt = this.translations.get("GAME_YES");
		String noTxt = this.translations.get("GAME_NO");
		if(GUI.getUserButtonPressed(this.translations.get("GUI_IN_PLAY_AGAIN"), yesTxt, noTxt)==yesTxt)
		return true;
		else return false;
	}
}
